package protocol.JT905_2014;

import java.util.HashMap;

public class Handle905_2014JT88 implements IHandle905_2014JT {
    @Override
    public String handle(JT_905_2014Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x01:
                return handle8801(cmd);
            case 0x02:
                return handle8802(cmd);
            case 0x03:
                return handle8803(cmd);
            case 0x05:
                return handle8805(cmd);
            default:
                return "905:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle8805(JT_905_2014Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:音频检索");
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"正常录音");
        list.put(1,"乘客投诉");
        list.put(2,"报警录音");
        builder.append("录音原因:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        builder.append("起始时间:"+cmd.readBCD(6));
        builder.append("\r\n");

        builder.append("结束时间:"+cmd.readBCD(6));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle8803(JT_905_2014Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:存储图像上传命令");
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"照片");
        list.put(1,"音频");
        list.put(2,"视频");
        builder.append("类型:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        builder.append("文件ID:"+cmd.readInt(4));
        builder.append("\r\n");

        builder.append("起始地址:"+cmd.readInt(4));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle8802(JT_905_2014Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:存储图像检索");
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();

        builder.append("摄像头ID(0表示检索全部摄像头):"+cmd.readInt(1));
        builder.append("\r\n");

        list.clear();
        list.put(0,"进入重车拍照");
        list.put(1,"服务评价拍照");
        list.put(2,"报警拍照");
        list.put(3,"中心主动拍照");

        builder.append("拍照原因："+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        builder.append("起始时间："+cmd.readBCD(6));
        builder.append("\r\n");
        builder.append("结束时间："+cmd.readBCD(6));
        builder.append("\r\n");
        return builder.toString();
    }

    private String handle8801(JT_905_2014Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:摄像头立即拍摄命令");
        builder.append("\r\n");

        builder.append("摄像头ID:"+cmd.readInt(1));
        builder.append("\r\n");

        builder.append("拍摄命令（0为停止拍摄，FFFF表示录像，其他表示" +
                "拍照张数）:"+cmd.readBCD(2));
        builder.append("\r\n");

        builder.append("拍照间隔/录像时间（0表示按最小拍照间隔或一直录像）:"+cmd.readInt(2));
        builder.append("\r\n");
        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"实时上传");
        list.put(1,"保存");
        builder.append("保存标志:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        list.clear();
        list.put(0,"320*240");
        list.put(1,"640*480");
        list.put(2,"800*600");

        builder.append("分辨率:"+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");

        builder.append("图像/视频质量（1～10，1最好）:"+cmd.readInt(1));
        builder.append("\r\n");

        builder.append("亮度（0～255）:"+cmd.readInt(1));
        builder.append("\r\n");
        builder.append("对比度（0～127）:"+cmd.readInt(1));
        builder.append("\r\n");
        builder.append("饱和度（0～127）:"+cmd.readInt(1));
        builder.append("\r\n");
        builder.append("色度（0～255）:"+cmd.readInt(1));
        builder.append("\r\n");


        return builder.toString();
    }
}
